extends Projectile


class_name Bullet


@onready var move: MoveComponent = $NamedComponent/Move/MoveComponent
@onready var hit_box: HitBoxComponent = $HitBoxComponent
@onready var timer: Timer = $Timer


func setup(arg: ProjectileResource) -> void:
    move.direction = arg.start_direction
    move.speed = arg.speed
    timer.wait_time = arg.limit_lifetime
    hit_box.collision_mask = arg.hit_layer_mask

    position = arg.start_position
    timer.start()

func teardown() -> void:
    pass

func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
    event_hit_out_of_screen.emit(self, move.direction)

func _on_hit_box_component_event_hit_something(hitbox: HitBoxComponent, body: Node2D, body_rid: RID, hit_normal: Vector2) -> void:
    event_hit_something.emit(self, body, body_rid, move.direction, hit_normal)

func _on_timer_timeout() -> void:
    event_hit_nothing.emit(self)
